﻿using UnityEngine;
using System.Collections;

public enum HexDirection
{

    NE, E, SE, SW, W, NW,Count

}

public static class HexDirectionExtensions
{
    public static HexDirection Opposite(this HexDirection direction)
    {
        return (int)direction < 3 ? (direction + 3) : (direction - 3);
    }
    public static HexDirection Previous(this HexDirection direction)
    {
        return direction == HexDirection.NE ? HexDirection.NW : (direction - 1);
    }

    public static HexDirection Next(this HexDirection direction)
    {
        return direction == HexDirection.NW ? HexDirection.NE : (direction + 1);
    }
}

public class HexCell{

    public HexCoordinate coordinates;
    public Color color;
    public Vector3 Position;
    public Vector3 LocalPosition;
    public int Index;
    public Vector3 hexCoord {
        get
        {
            return new Vector3(coordinates.X,coordinates.Y,coordinates.Z);
        }
    }

    HexCell[] neighbors = new HexCell[0];
       
    public HexCell GetNeighbor(HexDirection direction)
    {
        return neighbors[(int)direction];
    }

    public void SetNeighbor(HexDirection direction, HexCell cell)
    {
        if(neighbors.Length == 0)
        {
            neighbors = new HexCell[6];
        }
        if(cell.neighbors.Length == 0)
        {
            cell.neighbors = new HexCell[6];
        }
        neighbors[(int)direction] = cell;
        cell.neighbors[(int)direction.Opposite()] = this;
    }
}
